# Maintainer: Leonardo Arena <rnalrd@alpinelinux.org>
pkgname=pg_probackup
pkgver=2.5.11
_pgsqlver=15.2
_pgsqlverm="${_pgsqlver%%.[0-9]*}"
pkgrel=0
pkgdesc="Backup and recovery manager for PostgreSQL"
url="https://github.com/postgrespro/pg_probackup"
arch="all"
license="PostgreSQL"
makedepends="postgresql$_pgsqlverm postgresql$_pgsqlverm-dev zlib-dev readline-dev libxml2-utils libxslt"
source="pg_probackup-$pkgver.tar.gz::https://github.com/postgrespro/pg_probackup/archive/refs/tags/$pkgver.tar.gz
	https://ftp.postgresql.org/pub/source/v$_pgsqlver/postgresql-$_pgsqlver.tar.bz2"
builddir="$srcdir/postgresql-$_pgsqlver/contrib/pg_probackup-$pkgver"

prepare(){
	default_prepare

	mv "$srcdir"/pg_probackup-$pkgver "$srcdir"/postgresql-$_pgsqlver/contrib

	cd "$srcdir"/postgresql-$_pgsqlver
	./configure --without-ldap

	local _header
	for _header in $(ls "$srcdir"/postgresql-$_pgsqlver/src/bin/pg_basebackup/*.h); do
		ln -s $_header "$builddir"/src/
	done
}

build() {
	make -j1

	# fail to build
	# cd doc
	# xmllint --noout --valid probackup.xml
	# xsltproc stylesheet.xsl probackup.xml >pg-probackup.html
}

check() {
	local _tmp=$(mktemp -u)
	local _catalog="$(pwd)$_tmp"
	./pg_probackup version
	./pg_probackup init -B $_catalog
}

package() {
	install -Dm755 ./pg_probackup \
		"$pkgdir"/usr/bin/pg_probackup$_pgsqlverm
	# install -Dm644 "$builddir"/doc/pg-probackup.html "$pkgdir"/usr/share/doc/pg_probackup/pg-probackup.html
}

sha512sums="
8d78462cd03520a09b89cd95797a623669a76b78677d71d8819da07e634d48fb8948de23bb5bf02963c68e22f6e10913c86c0a27a5ae018159f6e563dc32d45e  pg_probackup-2.5.11.tar.gz
115a8a4234791bba4e6dcc4617e9dd77abedcf767894ce9472c59cce9d5d4ef2d4e1746f3a0c7a99de4fc4385fb716652b70dce9f48be45a9db5a682517db7e8  postgresql-15.2.tar.bz2
"
